package com.flyduck.system.controller;

import com.flyduck.common.annotation.IgnoreAuth;
import com.flyduck.common.vo.PageResult;
import com.flyduck.common.vo.Result;
import com.flyduck.system.service.SysPostService;
import com.flyduck.system.vo.post.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: flyduck-platform2
 * @description: 系统:职位接口
 * @author: flyduck
 * @create: 2021-03-05 17:42
 **/
@Api(tags = "系统:职位接口")
@RestController
@RequestMapping("/system/post")
public class SysPostController {

    @Autowired
    private SysPostService sysPostService;


    @ApiOperation("获取职位分页")
    @PostMapping("/page")
    public Result getPostPageList(@RequestBody SysPostReqVO reqVo,
                                   @RequestParam(value = "page",required = true) Integer page,
                                   @RequestParam(value = "size",required = true) Integer size){
        PageResult<SysPostRespVO> postPage = sysPostService.getPostPageList(reqVo, page, size);
        return Result.success(postPage);
    }

    @IgnoreAuth
    @ApiOperation("获取职位详情")
    @GetMapping("/detail")
    public Result getPostDetail(@RequestParam(value = "id",required = true) Long id){
        SysPostDetailRespVO respVO = sysPostService.getPostDetail(id);
        return Result.success(respVO);
    }

    @ApiOperation("新增职位")
    @PostMapping("/add")
    public Result addPost(@RequestBody @Validated SysPostAddReqVO reqVo){
        boolean flag = sysPostService.addPost(reqVo);
        return Result.success(flag,"新增成功");
    }

    @ApiOperation("编辑职位")
    @PutMapping("/update")
    public Result updatePost(@RequestBody @Validated SysPostUpdateReqVO reqVo){
        boolean flag = sysPostService.updatePost(reqVo);
        return Result.success(flag,"编辑成功");
    }

    @ApiOperation("删除职位")
    @DeleteMapping("/delete")
    public Result deletePost(@RequestParam(value = "id",required = true) Long id){
        boolean flag = sysPostService.deletePost(id);
        return Result.success(flag,"删除成功");
    }

    @IgnoreAuth
    @ApiOperation("获取职位下拉")
    @GetMapping("/select")
    public Result getPostSelect(){
        List<SysPostSelectRespVO> postList = sysPostService.getPostSelect();
        return Result.success(postList);
    }
}
